/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dabarobjects.mobile.database;
 
import java.util.Date;

/**
 * A RecordItem encapsulate a single entry in the mobile data store. It lines up its content in a sequence of string
 * pattern separated by special characters.
 *
 * @author Deji Aladejebi
 */
public final class RecordItem {

    private final String recordKey;
    private final Date timestamp;
    private final Object recordValue;
    private final int recordSequence;

     
    public RecordItem(String recordKey, Date timestamp, Object recordValue, int recordSequence) {
        this.recordKey = recordKey;
        this.timestamp = timestamp;
        this.recordValue = recordValue;
        this.recordSequence = recordSequence;
    }


    public String toString() {
        if(recordValue == null)
            return "";
        return recordValue.toString();//"RK:" + recordKey + ";" + "RS:" + recordSequence + ";" + "RV:" + recordValue + ";" + "TS:" + timestamp;
    } 

    public final String getRecordKey() {
        return recordKey;
    }

    public final int getRecordSequence() {
        return recordSequence;
    }

    public final String getRecordValue() {
        return recordValue.toString();
    }
    public final Date getRecordAsDate(){
        return (Date) recordValue;
    }
    public final Integer getRecordAsInteger(){
        return (Integer) recordValue;
    }

    public final Date getTimestamp() {
        return timestamp;
    } 

    public final boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RecordItem other = (RecordItem) obj;
        if ((this.recordKey == null) ? (other.recordKey != null) : !this.recordKey.equals(other.recordKey)) {
            return false;
        }
        return true;
    }

    public final int hashCode() {
        int hash = 7;
        hash = 19 * hash + (this.recordKey != null ? this.recordKey.hashCode() : 0);
        return hash;
    } 


}
